package org.geektimes.rest.demo;


import org.apache.commons.io.IOUtils;
import org.junit.Test;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;

/**
 * @Author: jipeng
 * @Description:
 * @Date: Created in 2021/3/30 7:50
 */
public class HttpUrlConnectionDemo {


    @Test
    public static void main(String[] args) throws Throwable {
        URI uri = new URI("http://localhost:8080/user/index");
        URL url = uri.toURL();

        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        try (InputStream inputStream = connection.getInputStream()) {
            System.out.println(IOUtils.toString(inputStream,"utf-8"));
        }
        //关闭连接
        connection.disconnect();

    }


}
